<!DOCTYPE html>
<!-- saved from url=(0022)http://localhost:8080/ -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta name="browsermode" content="application">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <!-- 禁止百度转码 -->
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <!-- uc强制竖屏 -->
    <meta name="screen-orientation" content="portrait">
    <!-- QQ强制竖屏 -->
    <meta name="x5-orientation" content="portrait">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta name="format-detection" content="telephone=no">
    <title>添加地址</title>
    <link rel="stylesheet" href="${request.contextPath}/web/css/reset.css?v=${verison!}">
    <link rel="stylesheet" href="${request.contextPath}/web/css/base.css?v=${verison!}">
    <link rel="stylesheet" href="${request.contextPath}/web/css/address-add.css?v=${verison!}">
    <link rel="stylesheet" href="${request.contextPath}/web/css/ydui.css">
    <link rel="stylesheet" href="${request.contextPath}/plug/layui/css/layui.css" media="all">
</head>
<body style="background-color: rgb(245, 245, 245);">
<div data-role="page">
    <div class="app">
        <div class="addAddress absolute router">
            <div class="list">
                <div class="item acea-row row-between-wrapper">
                    <div class="name">姓名</div>
                    <input type="text" placeholder="请输入姓名" required="required" id="userName" value="<#if data??>${data.userName}</#if>">
                </div>
                <div class="item acea-row row-between-wrapper">
                    <div class="name">联系电话</div>
                    <input type="text" placeholder="请输入联系电话" required="required" id="phone" value="<#if data??>${data.phone}</#if>">
                </div>
                <div class="item acea-row row-between-wrapper">
                    <div class="name">所在地区</div>
                    <input type="text" id="citySelect" placeholder="请选择收货地址" required="required" value="<#if data??>${data.address}</#if>">
                    <div class="iconfont icon-dizhi font-color-red"></div>
                </div>
                <div class="item acea-row row-between-wrapper">
                    <div class="name">详细地址</div>
                    <input type="text" placeholder="请填写具体地址" required="required" id="detail" value="<#if data??>${data.detail}</#if>">
                </div>
            </div>
            <div class="default acea-row row-middle">
                <div class="select-btn">
                    <div class="checkbox-wrapper">
                        <label class="well-check">
                            <input type="checkbox" name="" value="" id="isDefault" <#if data?? && data.isDefault==1>checked</#if>>
                            <i class="icon"></i><span class="def">设置为默认地址</span>
                        </label>
                    </div>
                </div>
            </div>
            <a class="keepBnt bg-color-red" onclick="save()">立即保存</a>
        </div>
    </div>
    <#include "include/right.html" />
</div>
</body>
<script type="text/javascript" src="${request.contextPath}/web/js/media_750.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/jquery.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/jquery.mobile.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/ydui.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/ydui.city.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/common.js"></script>
<script src="${request.contextPath}/js/layer.js"></script>
<script>
    var id = '<#if data??>${data.id}</#if>';
    var type = '<#if type??>${type!}</#if>';
    $(function () {
        var $target = $('#citySelect');
        $target.citySelect();
        $target.on('click', function (event) {
            event.stopPropagation();
            $target.citySelect('open');
        });

        $target.on('done.ydui.cityselect', function (ret) {
            $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
        });
    })
    function save(){
        var obj = new Object();
        obj["userName"] = $.trim($("#userName").val());
        obj["phone"] =  $.trim($("#phone").val());
        obj["address"] =  $.trim($("#citySelect").val());
        obj["detail"] =  $.trim($("#detail").val());
        obj["isDefault"] = $("#isDefault").prop("checked") ? 1 : 0;
        if("" == obj["userName"]){
            layer.msg("姓名不能为空！")
            return;
        }
        if("" == obj["phone"]){
            layer.msg("联系电话不能为空！")
            return;
        }
        if(!isPhoneNo(obj["phone"])){
            layer.msg("联系电话不正确！")
            return;
        }
        if("" == obj["address"]){
            layer.msg("收获地址不能为空！")
            return;
        }
        if("" == obj["detail"]){
            layer.msg("具体地址不能为空！")
            return;
        }
        var url = '${request.contextPath}/web/address/add';
        if(id != ""){
            obj["id"] = id;
            url = '${request.contextPath}/web/address/update';
        }
          $.ajax({
              type: 'POST',
              url: url,
              data: JSON.stringify(obj),
              dataType:'json',
              contentType:'application/json',
              success: function(data){
                  if(data.code==200){
                    if(type != ''){
                        window.location.href="${request.contextPath}/web/orderSubmit/"+type;
                    }else{
                        window.location.href="${request.contextPath}/web/addressList"
                    }
                  }else{
                     layer.msg(data.msg)
                  }
              }
        });
    }

</script>
</html>